//
//  NSArray+XY.m
//  ZhaoQiPei
//
//  Created by 找汽配 on 2017/2/16.
//  Copyright © 2017年 XiangYun. All rights reserved.
//

#import "NSArray+XY.h"

@implementation NSArray (XY)

- (NSArray<NSDictionary *> *)arrayWithIndexes:(NSArray<NSString *> *)indexes block:(NSString *(^)(id obj))block {
    NSMutableDictionary * mDict = [NSMutableDictionary dictionary];
    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * index = block(obj);
        if (!mDict[index]) {
            mDict[index] = [NSMutableArray array];
        }
        [mDict[index] addObject:obj];
    }];
    NSMutableArray * mArray = [NSMutableArray arrayWithCapacity:mDict.count];
    [indexes enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (mDict[obj]) {
            [mArray addObject:@{@"index":obj,
                                @"array":[mDict[obj] copy]}];
        }
    }];
    return [mArray copy];
}

@end
